package com.foreknow.demo15;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class SetDemo {
    public static void main(String[] args) {
        //创建一个Set集合容器
        Set<Student> s = new HashSet<>();
        //添加元素
        Student s1 = new Student();
        s1.setName("fender");
        Student s2 = new Student();
        s2.setName("gibson");
        Student s3 = new Student();
        s3.setName("yamaha");
        s.add(s1);
        s.add(s2);
        s.add(s2); //不能有重复的元素
        s.add(s3);
        //遍历set集合(迭代器)
        Iterator<Student> it = s.iterator();
        while (it.hasNext()) {
            Student ss = it.next();
            System.out.println(ss.getName() + "--" + ss.getPhone());
        }
    }
}
